package huffMan;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class HaffManFile {
	private static HuffManTree h;
	public static void main(String[] args) {
	    h = new HuffManTree(GenerateWeights("C:\\Users\\SELab\\Desktop\\test"));
		System.out.println(h.getCodes());
		
	}
	public static int[] GenerateWeights(String FileName) {
		int[]  content = new int[256];
		File file = new File(FileName);
		if(!file.exists()) return null;
		byte[] buffer = new byte[1024];
		FileInputStream fileInput = null;
		try {
			fileInput = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		int byteread = 0;
		try {
			while((byteread = fileInput.read(buffer)) != -1) {
				for(int i = 0;i < byteread; i++) content[buffer[i]]++;
			}
			
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

		return content;
	}
	public static void EncodeFile(File file) {
		FileInputStream fileInput = null;
		int byteread = 0;
		byte[] buffer = new byte[1024];
		/*
		try{
			fileInput = new FileInputStream(file);
			while((byteread = fileInput.read(buffer)) != -1){
				h.Encode(buffer);
			}
		}*/
		file.getName();
	}
	private static byte[] Str2Byte(String string){
		byte[] datas = string.getBytes();
		byte[] codes = new byte[(datas.length - 1)/8 + 1];
		int pow = 7;
		byte code = 0;//存储每一位的编码
		for(int i = 0; i < datas.length; i++){
			if(datas[i] == '1') code += Math.pow(datas[i], pow--);
			//if(pow == 0) 
		}
	}
}